import React, {Component} from "react";
import {findErrStubRecord} from "../../fetch/fetchApi";
import GridTable from '../../components/display/gridTable';
import { Tooltip } from 'antd';


class ErrRecordList extends Component {

    constructor (props) {
        super(props);
        this.props = props;
        this.state = {
            gridData: [],
            loading: !1,
            btnloading: !1,
            pagination: {
                total: 0
            }
        };
        this.init();
    }

    init () {
        this.query = {
            page: '1',
            pagecount: '10'
        };
        // 设置表头
        this.tableColumns = [
            {
                title: '上报时间',
                dataIndex: 'reportTime',
                key: 'reportTime'
            }, {
                title: '故障类型',
                dataIndex: 'errorType',
                key: 'errorType'
            }, {
                title: '故障明细',
                dataIndex: 'errorInfo',
                key: 'errorInfo',
                className: 'column-nowrap',
                render: (text, record) => (
                <Tooltip placement="topLeft" title={text} >
                    {text}
                </Tooltip>)
            }
        ];
    }

    componentDidMount () {
        this.buildingApplyCb();
    }

    // 故障记录列表
    async errRecordList () {
        this.setState({
            loading: !0,
            btnloading: !0
        });
        try {
            const resData = await findErrStubRecord({
                stubId: this.props.stubId,
                errorMode: this.props.errorMode,
                startTime: this.props.startTime,
                endTime: this.props.endTime,
                page: this.query.page,
                pagecount: this.query.pagecount
            });
            if (resData.data.code === '200') {
                const pagination = {
                    total: resData.data.pageLimit.totalCount,
                    onShowSizeChange: (current) => {
                        this.turnPage(current)
                    },
                    onChange:(current) => {
                        this.turnPage(current)
                    }
                }
                this.setState({
                    pagination
                });
                return resData.data.data;
            }
        } catch (e) {
            console.log(e);
        }
    }

    // 跳转页码
    turnPage (current) {
        this.query['page'] = current.toString();
        this.buildingApplyCb();
    }

    buildingApplyCb () {
        this.errRecordList().then((data) => {
            this.setState({
                loading: !1,
                btnloading: !1,
                gridData: data
            });
        });
    }

    render () {
        const Content = <div className="sc-page-content">
            <div className="page-panel">
                <GridTable postyle="table-center" data={this.state.gridData} columns={this.tableColumns} loading={this.state.loading} pagination={this.state.pagination}/>
            </div>
        </div>;

        return Content;
    }

}
export default ErrRecordList;